<!--组件-开放跟单设置-->
<template>
  <div>
    <div v-if="param">
      <VSwitc v-model="param.isFollow" :title="T('开放策略跟单')" @change="followClick"></VSwitc>
      <div class="height40" v-if="param.isFollow"></div>
      <text class="font28 main-t1" v-if="param.isFollow" @click="follwSetClick">{{T('更多跟单设置')+' >>'}}</text>
    </div>
  </div>
</template>

<script>
//组件
import VSwitc from "@/public/view/VSwitc.vue";

//功能
import navigator from "@/_js/navigator"; 
import broadcast from "@/_js/broadcast"; 
import math from "@/_js/math"; 
import mLimit from "@/up/amLimit"; 

const globalEvent = weex.requireModule('globalEvent');
const weexFunction = weex.requireModule('WeexFunction');

import I18N from "@/_i18n/i18n";
var T = I18N.t;

var normParam = {
  'isFollow':true, //true 开放跟单
  'followMap':undefined,
}

export default {

  components: {
    VSwitc,
  },


  model:{
    prop:"param",
    event:"change",
  },

  props:{
    param: Object,
    pairMaps: Array, //多币对

    investCoin:String, //投资币
    investNum:String, //投资数量
    pairMap:Object, //选中的交易对
    params:Object, //参数数组（投入限制联动使用）
    commissionMap:Object, //佣金

    type:String, //ai(ai启动) define(自定义启动) many(多币对启动)
    name:String, //网格、马丁、海浪、衡量定投、其他

    limitMap:Object, //限制
  },

  watch: {
    param: {
      deep: false,
      handler (val, oldVal) {
        this.initParam(val);
      }
    },
  },
  
  data() {
    return {
      T:T,
    };
  },

  mounted(){
    this.initParam(this.param);
  },

  methods:{

    //初始化参数
    initParam(param){

      if (param == undefined || JSON.stringify(param) == '{}') {
        this.param = JSON.parse(JSON.stringify(normParam));
        this.$emit("change", this.param); 
      }
    },

    /********************************** 点击触发*/
    //跟单点击
    followClick(){
      this.param.isFollow && this.$emit("follow");
    },

    //跟单设置
    follwSetClick() {

      //跟单限制
      var pairNum = this.pairMaps ? (this.pairMaps.length + 1) : undefined;
      var limit = mLimit.getInvestLimit(this.type, this.name, this.params, this.investCoin, this.pairMap, this.limitMap, pairNum);

      //折合USDT
      var investNum = this.investNum.length ? this.investNum : '0';
      var investUsdt = investNum;
      if (this.investCoin != 'USDT') {
        var xiaoshu = mLimit.getXiaoshu(this.investCoin, this.pairMap);
        var price = this.investCoin == this.pairMap.baseCoin ? this.pairMap.baseCoinUsdPrice : this.pairMap.usdPrice;
        investUsdt = math.cheng(investUsdt, price, xiaoshu, 2);
      }
      
      var parm = {
          investLimit:{'minInvest':'', 'maxInvest':''}, //投入限制
          followName:this.name, //默认跟单名称
          mark:[], //跟单标签
          commission:this.commissionMap.commission, //佣金
          isVtnEquity:this.commissionMap.isVtnEquity, //佣金是否包含权益
          };
      parm = this.param.followMap ? JSON.parse(JSON.stringify(this.param.followMap)) : parm;
      parm.investNum = investNum;
      parm.investUsdt = investUsdt;
      parm.investCoin = this.investCoin;
      parm.minInvestLimit = limit.min;
      parm.maxInvestLimit = limit.max;

      navigator.open('', 'up/FollowSet',parm);

      broadcast.subscribeOnce("FollowSet", (data)=>{
        this.param.followMap = data;
      });
    },
  }
}
</script>


<style src="@/_css/style.css"></style>
<style scoped>
.height40 {
  height: 40px;
}
</style>
